package cn.consult.controller.sys.park;

import cn.consult.common.api.CommonResult;
import cn.consult.sys.entity.SysDictDetail;
import cn.consult.sys.entity.TCheckEquipment;
import cn.consult.sys.service.TCheckEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "园区管理 > 考勤机管理")
@RequestMapping("/park/check")
public class TCheckEquipmentController {

    @Autowired
    TCheckEquipmentService tCheckEquipmentService;


    @ApiOperation("addCheck => 添加考勤机")
    @PostMapping("/addCheck")
    public CommonResult addCheck(@RequestBody TCheckEquipment tCheckEquipment) throws ParseException {
        boolean flag = tCheckEquipmentService.saveCheckFlag(tCheckEquipment);
        if (flag) {
            return CommonResult.success(flag);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("updateCheck => 修改考勤机")
    @PutMapping("/updateCheck")
    public CommonResult updateCheck(@RequestBody TCheckEquipment tCheckEquipment) {
        boolean flag = tCheckEquipmentService.updateChecklFlag(tCheckEquipment);
        if (flag) {
            return CommonResult.success(flag);
        } else {
            return CommonResult.failed();
        }
    }


    @ApiOperation("getCheckAll => 条件查询考勤机")
    @GetMapping("/getCheckAll")
    public CommonResult getCheckAll(@RequestParam Map<String, Object> params) {
        List<TCheckEquipment> list = tCheckEquipmentService.getCheckAll(params);
        return CommonResult.success(list);
    }

    @ApiOperation("delCheck => 删除考勤机")
    @DeleteMapping("/delCheck/{id}")
    public CommonResult delCheck(@PathVariable Long id) {
        boolean b = tCheckEquipmentService.removeById(id);
        return CommonResult.success(b);
    }

    @ApiOperation("getCheckById => 根据id查询考勤机")
    @GetMapping("/getCheckById/{id}")
    public CommonResult getCheckById(@PathVariable Long id) {
        TCheckEquipment byId = tCheckEquipmentService.getById(id);
        return CommonResult.success(byId);
    }
}
